<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--订单数据-->
      <el-col :span="24" :xs="24">
        <!-- 搜索 -->
        <template>
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="客户ID" prop="customerUserId">
              <el-input
                v-model="queryParams.customerUserId"
                placeholder="客户ID"
                clearable
                style="width: 240px"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="店铺ID" prop="shopId" v-if="$store.getters && $store.getters.admin">
              <el-input
                v-model="queryParams.shopId"
                placeholder="请输入店铺ID"
                clearable
                style="width: 240px"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="创建时间">
              <el-date-picker
                v-model="dateRange"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </template>

        <!-- 按钮操作栏 -->
        <template>
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button
                type="danger"
                plain
                icon="el-icon-delete"
                size="mini"
                :disabled="multiple"
                @click="handleDelete"
                v-hasPermi="['customer:report:remove']"
              >删除</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>
        </template>

      </el-col>
    </el-row>

    <!-- 表格 -->
    <template>
      <el-table v-loading="loading" :data="reportList" @selection-change="handleSelectionChange" @sort-change="handleSortChange">
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="ID" align="center" key="reportId" prop="reportId" :show-overflow-tooltip="true" />
        <el-table-column label="客户ID" align="center" key="customerUserId" prop="customerUserId" :show-overflow-tooltip="true" />
        <el-table-column label="关联动态Id" align="center" key="dynamicId" prop="dynamicId" :show-overflow-tooltip="true" />
        <el-table-column label="分类类型" align="center" key="reportType" prop="reportType" :show-overflow-tooltip="true"/>
        <el-table-column label="内容" align="center" key="reportContent" prop="reportContent" :show-overflow-tooltip="true"/>
        <el-table-column label="联系方式" align="center" key="reportContact" prop="reportContact" :show-overflow-tooltip="true"/>
        <el-table-column label="图片" align="center" key="reportImages">
          <template slot-scope="scope">
            <div class="flex" v-if="scope.row.reportImages">
              <!-- <el-avatar shape="square" size="medium" :src="v" alt="404" v-for="v in scope.row.reportImages.split(',')" class="mgr5"></el-avatar> -->
              <el-image style="width: 50px; height: 50px" :src="v" :preview-src-list="scope.row.reportImages.split(',')" v-for="v in scope.row.reportImages.split(',')" class="mgr5"></el-image>
            </div>
            <div v-else>-</div>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" sortable="custom" :sort-orders="['descending', 'ascending']" width="160">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          width="160"
          fixed="right"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row,scope.index)"
              v-hasPermi="['customer:report:query']"
            >详细</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['customer:report:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </template>
   
    <!-- 详细 -->
    <el-dialog title="详细" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px" size="mini">
        <el-row>
          <el-col :span="24">
            <el-form-item label="内容">{{ form.reportContent }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="图片">
              <div class="flex" v-if="form.reportImages">
                <!-- <el-avatar shape="square" size="medium" :src="v" alt="404" v-for="v in scope.row.reportImages.split(',')" class="mgr5"></el-avatar> -->
                <el-image style="width: 50px; height: 50px" :src="v" :preview-src-list="form.reportImages.split(',')" v-for="v in form.reportImages.split(',')" class="mgr5"></el-image>
              </div>
              <div v-else>-</div>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="联系方式">{{ form.reportContact }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listReport, delReport } from "@/api/customer/report";

export default {
  name: "Report",
  dicts: ['sys_normal_disable', 'app_service_audit_status'],
  components: { },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      reportList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 默认密码
      initPassword: undefined,
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerUserId: undefined,
        shopId: undefined,
      },
      // 表单校验
      rules: {
      }
    };
  },
  watch: {
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listReport(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.reportList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderNo: undefined,
        reportPrice: undefined,
        reportPriceNight: undefined,
        goodsTitle: undefined,
        reportEmployeeLevel: undefined,
        goodsUnitId: undefined,
        goodsProjectId: undefined,
        status: "0",
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderNo);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.open = true;
      this.form = row;
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const reportIds = row.reportId || this.ids;
      this.$modal.confirm('是否确认删除ID为"' + reportIds + '"的数据项？').then(function() {
        return delReport(reportIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
};
</script>